#include "SPI.h"

void DS1302WriteByte(unsigned char dat)
{
	unsigned char i;
	for (i = 0; i < 8; i++)//低位在前，高位在后
	{
		DS1302_IO = dat & 0x01;
		dat >>= 1;
		SCLK = 1;//上升沿DS1302采样，单片机把数据放到总线上
		SCLK = 0;
	}
}

unsigned char DS1302ReadByte()
{
	unsigned char tmp;
	unsigned char dat = 0;
	for(tmp = 0x01; tmp != 0; tmp <<= 1)
	{
		if(DS1302_IO != 0)
		{
			dat |= tmp; 
		}
		SCLK = 1;//上升沿 单片机来采样读  数据是DS1302输出到总线上
		SCLK = 0;
	}
	return dat;
	
}